/**
 * Created by fangjiahui on 15/12/4.
 */
// 所有模块都通过 define 来定义
define(function (require, exports, module) {

	if($("#conut").val()=="true"||$("#conut").val()==true){
		$("#validCodeApp").html('<div  class="inputCode"><img src="/validimg.html?t='+ Math.random()+'" align="absmiddle" style="float: right; margin: 5px 10px;" alt="点击刷新"   onClick="this.src=\'/validimg.html?t=' + Math.random()+'\'"/><input id="validCode" maxlength="256" class="inputText" type="text" placeholder="请输入验证码" name="validCode" style="width: 180px;"></div>');
	}
	
    $("#loginHome").validate({
        rules: {
            'userName': {
                required: true,
                //remote: {
                //    type: "get",
                //    url: "/app/user/checkUsername.html",
                //    dataType: "json",
                //    data: {
                //        userName: function () {
                //            return $("#userName").val();
                //        }
                //    }
                //}
            },
            'pwd': {
                required: true,
				regexPassword:true
            },
            'validCode':{
            	required: true
            }
        },
        messages: {
            'userName': {
                required: "请输入用户名"
            },
            'pwd': {
                required: "请输入密码",
				regexPassword:"密码格式错误"
            },
            'validCode':{
            	required: "请输入验证码"
            }
        },
        /*errorPlacement:function(error,element){
			element.parent("div").find("span").html(error);
	    },*/
        submitHandler: function (form, event, validator) {
            $(form).ajaxSubmit(function (data) {
                var result = data.result;
                if (result) {
                    $.post("/mobile/cooperation/add.html",
                        function (data) {
                            var redirectURL = $("#redirectURL").val();
                            if (redirectURL.trim().length > 0) {
                                window.location.href = redirectURL;
                            } else {
                                window.location.href = "/mobile/usercenter/main.html";
                            }
                        }
                    );
                } else {
                    if (data.count == true) {
                        $("#validCodeApp").html('<div  class="inputCode"><img src="/validimg.html?t=' + Math.random() + '" align="absmiddle" style="float: right; margin: 5px 10px;" alt="点击刷新"   onClick="this.src=\'/validimg.html?t=' + Math.random() + '\'"/><input id="validCode" maxlength="256" class="inputText" type="text" placeholder="请输入验证码" name="validCode" style="width: 220px;"></div>');
                    }
                    $('#validCodeApp img').attr('src', '/validimg.html?t=' + Math.random());
                    layer.alert(data.msg);
                }
            });
        }
    });

    //var Spinning = require('./spinning');

    // 通过 exports 对外提供接口
    //exports.doSomething = ...

    // 或者通过 module.exports 提供整个接口
    //module.exports = ...

});